package com.example.ecas.persistence;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.ecas.pojo.DisRcase;
import com.example.ecas.pojo.DisRtag;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface DisRtagMapper extends BaseMapper<DisRtag> {

    // 获取指定病类id的 病类-Tag联系
    default List<DisRtag> getDisRtagByDis(int disId) {
        QueryWrapper<DisRtag> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("dis_id", disId);
        return this.selectList(queryWrapper);
    }

    // 获取指定tag id的 病类-tag联系
    default List<DisRtag> getDisRtagByTag(int tagId) {
        QueryWrapper<DisRtag> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("tag_id", tagId);
        return this.selectList(queryWrapper);
    }

    // 新增一个 病类-tag联系
    default int addDisRtag(DisRtag disRtag) {
        if (disRtag == null) {
            return 0;
        }
        return this.insert(disRtag);
    }

    // 删除一个联系
    default int deleteDisRtag(DisRtag disRtag) {
        QueryWrapper<DisRtag> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("dis_id", disRtag.getDisId()).eq("case_id", disRtag.getTagId());
        return this.delete(queryWrapper);
    }
}
